



import { CreateNode } from "./CreateNode";
import { Map } from "./Map";
import { AllData } from "./Alldata";
import { GameControl } from "./GameControl";





const {ccclass, property} = cc._decorator;

@ccclass
export  class Main extends cc.Component {

    
    /** 所有数据 */
    public static AllData = new AllData();

    /** 地图节点 */
    private static mapNode:cc.Node = null;

    public static Map:Map = null;

    public static gameControl:GameControl;

    onLoad () {

        this.node.setContentSize(1080,1920);
        this.initLoadres();
    }

    private initLoadres (){

        let self = this;
        cc.loader.loadResDir("main",(error,data)=>{

            if(error){

            }else{
                console.log("资源加载成功");
                self.initMaps();
            }
        })
    }

    /** 绘制地图 */
    private initMaps(){
        
        Main.mapNode = new cc.Node("mapNode");
        this.node.addChild(Main.mapNode);
        Main.Map =  Main.mapNode.addComponent(Map);       
        Main.gameControl = new GameControl(Main.mapNode,Main.Map);
        Main.gameControl.init();
    }

    start () {

    }

    public static CountCallback(count:number,callback:Function){
        let countnum:number = count;
        let tempCall = ()=>{
           --countnum;
           cc.log(countnum);
           if (countnum === 0){

               callback && callback();
           }
       }
       return tempCall;
    }

    // update (dt) {}
}
